#pragma once
#include "mapispi.h"
#include "MsgStore.h"

// class IJApplication;

class CMSProvider :
	public IMSProvider
{
	///////////////////////////////////////////////////////////////////////////////
	// Interface virtual member functions
	//
public:
	STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);

	inline STDMETHODIMP_(ULONG) AddRef()
	{
		EnterCriticalSection (&m_csObj);
		++m_cRef; ULONG ulCount = m_cRef;
		LeaveCriticalSection (&m_csObj);
		return ulCount;
	}

	inline STDMETHODIMP_(ULONG) Release()
	{
		EnterCriticalSection (&m_csObj);
		ULONG ulCount = --m_cRef;
		LeaveCriticalSection (&m_csObj);
		if (!ulCount){
			delete this;
		}
		
		return ulCount;
	}

	MAPI_IMSPROVIDER_METHODS(IMPL);

	CMSProvider(HINSTANCE hInst);
	~CMSProvider(void);

	///////////////////////////////////////////////////////////////////////////////
	// Other member functions specific to this class
	//
	void WINAPI AddStoreObjectToList(CMsgStore * pMsgStoreObj);
	void WINAPI RemoveOpenStoreObject(CMsgStore * pStore);
	STDMETHODIMP GetProfileProps(LPMAPISUP pSupObj, LPSPropValue * ppProps, HWND hOwnerWnd);
	BOOL WINAPI IsStoreAlreadyOpen(LPSTR szServer, CMsgStore ** ppStoreObj);

	///////////////////////////////////////////////////////////////////////////////
	// Data members
	//
private:
	ULONG m_cRef; 
	CMsgStore * m_pMsgStoreList;
// 	std::list<CMsgStore *> m_pMsgStoreList;
	IJApplication * m_lpServer;
	CRITICAL_SECTION m_csObj;

public :
	HINSTANCE m_hInstance;
};
